<template>
    <CommonPage :tableConfig="option" ref="dataAuthRef" formKey="dataAuthorization"></CommonPage>
    <ElDialog v-model="dialog" width="600px" title="详情">
        <DataAuthorizationDetail v-if="dialog" :rowInfo="rowInfo"/>
    </ElDialog>
</template>
<script setup>
import CommonPage from '@/components/CommonPage/index.vue'
import DataAuthorizationDetail from './components/dataAuthorizationDetail.vue'
import { reactive, ref } from 'vue';
import {ElDialog } from 'element-plus'
import {platform} from "@/utils/enum.js"
import {adornUrl} from "@/utils"
import {getToken} from '@/utils/auth.js'

const dataAuthRef = ref()
const dialog = ref(false)
const rowInfo = ref()
const option = reactive({
    formItems: [
        {label: '客户企业名称', prop: 'custName', type: 'input', show: true},
        {label: '渠道名称', prop: 'channelName', type: 'input', show: true},
        {label: '产品名称', prop: 'productName', type: 'input', show: true},
        {label: '电商平台', prop: 'eBusinessPlatform', type: 'select', show: true, options: platform}
    ],
    buttons: [
        {label: "导出", icon: 'Download', auth: '', handle: (event)=> {download()}},
    ],
    options: [
        {label: '详情', handle: (event) => {handleDetail(event)}, isShow:() => {return true}},
    ]
})
// 下载
const download = () => {
    let params = JSON.parse(JSON.stringify(dataAuthRef.value.tableConfig.formData||"{}"))
    params.fileTitleName = dataAuthRef.value.tableConfig.columns.filter(item => item.show).map(item => item.prop).join(",")
    let str = ''
    for(let key in params) {
        str+=('&'+key+'='+params[key])
    }
    let url = adornUrl('/generator/orderauthorizationinfo/exportFile?token=')+getToken()+str
    window.open(url)
}
// 查看详情
const handleDetail = (info) => {
    rowInfo.value = info
    dialog.value = true
}
</script>